package com.qf.springcloud.mq;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class StreamQueueListener {

    @StreamListener(value = "stream-queue")
    public void consume(String msg,
                        @Header(name = AmqpHeaders.CHANNEL) Channel channel,
                        @Header(name = AmqpHeaders.DELIVERY_TAG)Long deliveryTag) throws IOException {
        // 手动ack需要channel和De...everyTag
        System.out.println("Stream接收到消息：" + msg);

        // 手动ack
        channel.basicAck(deliveryTag,false);
    }

}
